﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Net.Mail;
namespace NC.Core.Models
{
    public class AccountUser
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string MiddleName { get; set; }
        public string LastName { get; set; }
        [DataType(DataType.EmailAddress)]
        public string Email { get; set; }
        [DataType(DataType.Password)]
        public string Password { get; set; }
        public string ActivationCode { get; set; }
        public bool Active { get; set; }

        public void ActivateUser()
        {
            Active = true;
        }

        public void GenerateActivationCode()
        {
            var random = new Random();
            ActivationCode = string.Concat(FirstName, random.Next(NcConstants.RanNumMin, NcConstants.RanNumMax));
        }

        public MailMessage GetUserActivationMessage()
        {
            var emailTemplateService = new EmailTemplateService();
            var emailTemplate = emailTemplateService.GetEmailTemplateByName(TemplateName.UserActivation.ToString());
            var mail = new MailMessage(NcConstants.NcEmail, Email)
            {
                Body = emailTemplate.EmailBody + NcConstants.ActivationUrl + ActivationCode,
                Subject = emailTemplate.Subject,
                IsBodyHtml = true,
                BodyEncoding = System.Text.Encoding.GetEncoding("utf-8")
            };
            return mail;
        }
    }
}
